package com.zline.foodraise.view;

import android.content.Context;
import android.support.v7.widget.CardView;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zline.foodraise.R;
import com.zline.foodraise.entity.MsgBean;
import com.zline.foodraise.listener.RecyclerItemClicked;
import com.zline.foodraise.listener.RippleForegroundListener;
import com.zline.foodraise.ui.activity.MsgCentreActivity;

import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

/**
 * Created by heshantao on 15/11/13.
 * 消息中心Item
 */
@EViewGroup(R.layout.msg_centre_list_item)
public class MsgCentreItem extends RelativeLayout {
    private static final String LOG_TAG = MsgCentreActivity.class.getSimpleName();
    Context cxt;
    //消息标题
    @ViewById(R.id.msg_title_tv)
    TextView title_tv;
    //消息内容
    @ViewById(R.id.msg_content_tv)
    TextView content_tv;
    @ViewById(R.id.msg_centre__list_cv)
    CardView cardView;
    @ViewById(R.id.msg_look_detail_btn)
    Button btn;
    RecyclerItemClicked itemClicked;
    int position;


    public MsgCentreItem(Context context) {
        super(context);
        this.cxt = context;
    }

    public void bind(MsgBean bean, int position) {
        this.position = position;
        RippleForegroundListener listener = new RippleForegroundListener();
        listener.setView(cardView);
        btn.setOnTouchListener(listener);
        if (bean != null) {
            String title = bean.getTitle();
            String content = bean.getContent();
            int linkType = bean.getLinkType();
            title_tv.setText(title);
            content_tv.setText(content);
            if (linkType == 2) {
                btn.setText(R.string.look_raise_detail);
            } else if (linkType == 6 || linkType == 7) {
                btn.setText(R.string.look_order_detail);
            }

        }
    }

    @Click(R.id.msg_look_detail_btn)
    void onClick() {
        itemClicked.onRecyclerItemClicked(position);
    }

    public void setRecycleItemClickListener(RecyclerItemClicked itemClickListener) {
        this.itemClicked = itemClickListener;
    }
}
